<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head xmlns:th="http://www.thymeleaf.org" th:include="master::head">
    <title>添加PageInfo</title>
</head>
<body>
<div class="container">
    <div class="row">
        <form class="form" action="savePageInfo" method="post">
            <div class="form-body">
                <div class="form-group">
                    <label class="control-label">页面URL</label>
                    <input type="text" class="form-control" id="pageUrl" name="pageUrl"
                           value="http://floor.0731fdc.com/jggs.php" required="required"
                           placeholder="输入网页URL"/>
                    <!--<button type="button" class="btn primary query">规则查询</button>-->
                </div>
                <div class="form-group">
                    <label class="control-label">Url正则表达式</label>
                    <input type="text" class="form-control" id="urlRgx" name="urlRgx" required="required"/>
                </div>
                <div class="form-group">
                    <label class="control-label">是否JS渲染</label>
                    <select name="isJsRendering" class="select bootstrap-select bs-select">
                        <option value="0" selected="selected">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="control-label">请求方式</label>
                    <select id="requestMethod" name="method" class="bootstrap-select bs-select">
                        <option value="GET" selected="selected">get方式</option>
                        <option value="POST">post方式</option>
                        <option value="PUT">put方式</option>
                        <option value="DELETE">delete方式</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="control-label">请求参数（JSON）</label>
                                <textarea id="urlParamsJson" name="paramsJson" class="form-control " rows="3" value="{
'name':'yuananyn'
                                }"></textarea>
                </div>
                <div class="form-group">
                    <label class="control-label">页面验证解析表达式</label>
                    <input type="text" class="form-control" id="pageValidationRule" name="pageValidationRule"
                           value=""/></div>
            </div>
            <div class="form-actions">
                <button id="btnValidation" type="button" class="btn green test">测试页面验证表达式</button>
                <button id="btnSubmit" type="submit" class="btn blue save">保存</button>
            </div>
        </form>
        <textarea class="testResult form-control " rows="7"></textarea>
    </div>

</div>
<script th:inline="javascript">
    /*<![CDATA[*/
    $(function () {
        $("#btnValidation").click(function() {
            var form = $(this).closest("form");
            var data = {};
            form.serializeArray().map(function (x) {
                data[x.name] = x.value;
            });
            $.ajax({
                type: "post",
                cache: false,
                contentType: "application/json",
                url: global.contextPath + "/testPageValidation?random="+Math.random(),
                data: JSON.stringify(data),
                dataType: 'text',
                success: function (result) {     //回调函数，result，返回值
                    $(".testResult").val(JSON.stringify(result, null, "\t"));
                },
                error: function (msg) {
                    alert("测试出现异常！");
                    console.log(msg);
                }
            });
        });
        $(".form").submit(function () {
            var form = $(this);
            var data = {};
            form.serializeArray().map(function (x) {
                data[x.name] = x.value;
            });
            $.ajax({
                type: "post",
                cache: false,
                contentType: "application/json",
                url: form.attr("action"),
                data: JSON.stringify(data),
                dataType: 'json',
                success: function (data) {     //回调函数，result，返回值
//                    form.resetForm();
                    alert(data == true ? "提交成功!" : "提交失败！");
                },
                error: function (msg) {
                    alert("提交出现异常！");
                    console.log(msg);
                }
            });
            return false;
        });
    });

    /*]]>*/
</script>

</body>
</html>